<?php

namespace Common\Model;
use Think\Model;
class CaozuologModel extends Model{
	//新增管理员操作历史
	public function addLog($username,$content){
		$data = [
			'username'=>$username,
			'dotime'=>time(),
			'content'=>$content,
			'ip'=>get_client_ip(),
		];
		return $this->add($data);
	}
	public function getAllLog($username,$order,$content,$begin,$last,$page=0,$num=10){
		$where = [];
		if(empty($page)){
			$page = 1;
		}
		if(!empty($content)){
			$where['content'] = ['like','%'.$content.'%'];
		}
		if(!empty($username)){
			$where['username'] = ['like','%'.$username.'%'];
		}
		if(empty($begin)){
			$begin = 0;
		}else{
			$begin = $begin/1000;
		}
		if(empty($last)){
			$last = time();
		}else{
			$last = $last/1000+24*3600;
		}
		$where['dotime'] = ['between',[$begin,$last]];
		$count = $this->where($where)->count();
		$data = $this->where($where)->limit(($page-1)*$num,$num)->order($order)->select();
		return ['count'=>$count,'data'=>$data,'status'=>1];
	}
}

?>